/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI_SIFACT;

import AccesoDatosAvanzado.AD_Categoria;
import AccesoDatosSimple.cCategoria;
import GUI_Busquedas.Frm_busq_categoria;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import sifact.conexion.cConexion;

/**
 *
 * @author Cyber Huevadictos
 */
public class Frm_Categoria extends javax.swing.JFrame {

    private String txtnulos = "Los Campos Vacios son:\n";

    /**
     * Creates new form Frm_Categoria
     */
    public Frm_Categoria() {
        setDefaultLookAndFeelDecorated(true);
        this.addFocusListener(null);
        initComponents();
    }
//funcion para limpiar los campos

    private void CamposClean() {
        jTextFieldCodigo.setText(null);
        jTextFieldNomCategoria.setText(null);
    }
//funcion para bloquear campos cuando es Insercion

    private void CamposInsert() {
        //texto
        jTextFieldNomCategoria.setEnabled(true);
        jTextFieldGDistrib.setEnabled(true);
        jTextFieldGCF.setEnabled(true);
        //botones
        jButtonBuscar.setEnabled(false);
        jButtonAceptar.setEnabled(true);
    }
//funcion para bloquear campos cuando es Actualizacion

    private void CamposUpdate() {
        //texto        
        jTextFieldNomCategoria.setEnabled(true);
        jTextFieldGDistrib.setEnabled(true);
        jTextFieldGCF.setEnabled(true);
        //botones
        jButtonBuscar.setEnabled(true);
        jButtonAceptar.setEnabled(false);
    }
//funcion para bloquear campos cuando es Eliminacion

    private void CamposDelete() {
        //texto
        jTextFieldNomCategoria.setEnabled(false);
        jTextFieldGDistrib.setEnabled(false);
        jTextFieldGCF.setEnabled(false);
        //botones
        jButtonBuscar.setEnabled(true);
        jButtonAceptar.setEnabled(false);
    }
    
//funcion que me permite verificar los campos nulos del formulario
    
    private boolean CamposNulos() {
        boolean band = false;

        if (jTextFieldNomCategoria.getText().trim().equals("")) {
            txtnulos = txtnulos + "DESCRIPCION\n";
            band = true;
        }
        if (jTextFieldGDistrib.getText().trim().equals("")) {
            txtnulos = txtnulos + "GANANCIA DISTRIBUIDOR\n";
            band = true;
        }
        if (jTextFieldGCF.getText().trim().equals("")) {
            txtnulos = txtnulos + "GANANCIA CONSUMIDOR FINAL\n";
            band = true;
        }
        return band;
    }

    private void DatosFormulario(cCategoria obj1) {
        obj1.setTxtNombreCategoria(jTextFieldNomCategoria.getText().toUpperCase());
        obj1.setNumIDCategoria(Integer.parseInt(jTextFieldCodigo.getText()));
        obj1.setNumGDistribuidor(Double.parseDouble(jTextFieldGDistrib.getText()));
        obj1.setNumGCF(Double.parseDouble(jTextFieldGCF.getText()));
    }
    //Asigno los datos devueltos en una busqueda    

    private void DatosFormularioBusqueda(String obj) throws Exception {
        String[] tupla = new String[10];
        tupla = AD_Categoria.BuscarCodigo(obj);
        jTextFieldCodigo.setText(tupla[0]);
        jTextFieldNomCategoria.setText(tupla[1]);  
        jTextFieldGDistrib.setText(tupla[2]);
        jTextFieldGCF.setText(tupla[3]);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanelOpciones = new javax.swing.JPanel();
        jRadioButtonInsert = new javax.swing.JRadioButton();
        jRadioButtonUpdate = new javax.swing.JRadioButton();
        jRadioButtonDelete = new javax.swing.JRadioButton();
        jButtonBuscar = new javax.swing.JButton();
        jPanelBotones = new javax.swing.JPanel();
        jButtonAceptar = new javax.swing.JButton();
        jButtonCancelar = new javax.swing.JButton();
        jTabbedPaneDatos = new javax.swing.JTabbedPane();
        jPanelDatos = new javax.swing.JPanel();
        jLabelCodigo = new javax.swing.JLabel();
        jTextFieldCodigo = new javax.swing.JTextField();
        jLabelNomCategoria = new javax.swing.JLabel();
        jTextFieldNomCategoria = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jTextFieldGDistrib = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jTextFieldGCF = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("CATEGORIA DE PRODUCTOS");

        jPanelOpciones.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "OPCIONES PARA CATEGORIA DEL PRODUCTO", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 18))); // NOI18N

        buttonGroup1.add(jRadioButtonInsert);
        jRadioButtonInsert.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jRadioButtonInsert.setText("AGREGAR");
        jRadioButtonInsert.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jRadioButtonInsertMouseClicked(evt);
            }
        });

        buttonGroup1.add(jRadioButtonUpdate);
        jRadioButtonUpdate.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jRadioButtonUpdate.setText("MODIFICAR");
        jRadioButtonUpdate.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jRadioButtonUpdateMouseClicked(evt);
            }
        });

        buttonGroup1.add(jRadioButtonDelete);
        jRadioButtonDelete.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jRadioButtonDelete.setText("ELIMINAR");
        jRadioButtonDelete.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jRadioButtonDeleteMouseClicked(evt);
            }
        });

        jButtonBuscar.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButtonBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/16Nuvola_search_person.png"))); // NOI18N
        jButtonBuscar.setText("BUSCAR");
        jButtonBuscar.setEnabled(false);
        jButtonBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBuscarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelOpcionesLayout = new javax.swing.GroupLayout(jPanelOpciones);
        jPanelOpciones.setLayout(jPanelOpcionesLayout);
        jPanelOpcionesLayout.setHorizontalGroup(
            jPanelOpcionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelOpcionesLayout.createSequentialGroup()
                .addContainerGap(10, Short.MAX_VALUE)
                .addGroup(jPanelOpcionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanelOpcionesLayout.createSequentialGroup()
                        .addComponent(jRadioButtonInsert)
                        .addGap(69, 69, 69)
                        .addComponent(jRadioButtonUpdate))
                    .addComponent(jButtonBuscar))
                .addGap(76, 76, 76)
                .addComponent(jRadioButtonDelete)
                .addContainerGap())
        );
        jPanelOpcionesLayout.setVerticalGroup(
            jPanelOpcionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelOpcionesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelOpcionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jRadioButtonInsert)
                    .addComponent(jRadioButtonUpdate)
                    .addComponent(jRadioButtonDelete))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 13, Short.MAX_VALUE)
                .addComponent(jButtonBuscar))
        );

        jPanelBotones.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jButtonAceptar.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButtonAceptar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/16px-Crystal_Clear_action_apply.png"))); // NOI18N
        jButtonAceptar.setText("ACEPTAR");
        jButtonAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAceptarActionPerformed(evt);
            }
        });

        jButtonCancelar.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButtonCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/16px-Crystal_Clear_action_button_cancel.png"))); // NOI18N
        jButtonCancelar.setText("CANCELAR");
        jButtonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelBotonesLayout = new javax.swing.GroupLayout(jPanelBotones);
        jPanelBotones.setLayout(jPanelBotonesLayout);
        jPanelBotonesLayout.setHorizontalGroup(
            jPanelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelBotonesLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButtonAceptar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 54, Short.MAX_VALUE)
                .addComponent(jButtonCancelar)
                .addContainerGap())
        );
        jPanelBotonesLayout.setVerticalGroup(
            jPanelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelBotonesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonAceptar)
                    .addComponent(jButtonCancelar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPaneDatos.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabelCodigo.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabelCodigo.setText("CODIGO:");

        jTextFieldCodigo.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jTextFieldCodigo.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jTextFieldCodigo.setEnabled(false);
        jTextFieldCodigo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextFieldCodigoKeyTyped(evt);
            }
        });

        jLabelNomCategoria.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabelNomCategoria.setText("NOMBRE:");

        jTextFieldNomCategoria.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jTextFieldNomCategoria.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jTextFieldNomCategoria.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextFieldNomCategoriaKeyTyped(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel1.setText("GANANCIA DISTRIBUIDOR (%):");

        jTextFieldGDistrib.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jTextFieldGDistrib.setText("00.00");
        jTextFieldGDistrib.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextFieldGDistribKeyTyped(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel2.setText("GANANCIA CONSUMIDOR FINAL (%):");

        jTextFieldGCF.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jTextFieldGCF.setText("00.00");
        jTextFieldGCF.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextFieldGCFKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout jPanelDatosLayout = new javax.swing.GroupLayout(jPanelDatos);
        jPanelDatos.setLayout(jPanelDatosLayout);
        jPanelDatosLayout.setHorizontalGroup(
            jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDatosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelDatosLayout.createSequentialGroup()
                            .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabelNomCategoria)
                                .addComponent(jLabelCodigo))
                            .addGap(18, 18, 18)
                            .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jTextFieldCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jTextFieldNomCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, 334, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(jPanelDatosLayout.createSequentialGroup()
                            .addComponent(jLabel1)
                            .addGap(18, 18, 18)
                            .addComponent(jTextFieldGDistrib, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanelDatosLayout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(18, 18, 18)
                        .addComponent(jTextFieldGCF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanelDatosLayout.setVerticalGroup(
            jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDatosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelCodigo)
                    .addComponent(jTextFieldCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelNomCategoria)
                    .addComponent(jTextFieldNomCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextFieldGDistrib, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextFieldGCF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPaneDatos.addTab("DATOS  DE LA CATEGORIA", jPanelDatos);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanelOpciones, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jTabbedPaneDatos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(67, 67, 67)
                .addComponent(jPanelBotones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanelOpciones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jTabbedPaneDatos, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanelBotones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jRadioButtonInsertMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jRadioButtonInsertMouseClicked
        // TODO add your handling code here:
        CamposInsert();
        CamposClean();
        int e;
        try {
            e = AD_Categoria.GetId();
            e += 1;
            if (e >= 0) {
                jTextFieldCodigo.setText(Integer.toString(e));
            } else {
                JOptionPane.showMessageDialog(null, "Existe el siguiente error:\n" + e, "ERROR AL OBTENER CODIGO", JOptionPane.ERROR_MESSAGE);
            }
            cConexion.cerrar();
        } catch (Exception ex) {
            Logger.getLogger(Frm_Clientes.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jRadioButtonInsertMouseClicked

    private void jRadioButtonUpdateMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jRadioButtonUpdateMouseClicked
        // TODO add your handling code here:
        CamposUpdate();
        CamposClean();
    }//GEN-LAST:event_jRadioButtonUpdateMouseClicked

    private void jRadioButtonDeleteMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jRadioButtonDeleteMouseClicked
        // TODO add your handling code here:
        CamposDelete();
        CamposClean();
    }//GEN-LAST:event_jRadioButtonDeleteMouseClicked

    private void jButtonBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonBuscarActionPerformed
        // TODO add your handling code here:
        if (jRadioButtonUpdate.isSelected() == true || jRadioButtonDelete.isSelected() == true) {
            String objcadena = "";
            Frm_busq_categoria.setDefaultLookAndFeelDecorated(true);
            Frm_busq_categoria obj;
            try {
                obj = new Frm_busq_categoria(null, true, objcadena);
                obj.setVisible(true);
                if (!obj.getObjcadena().equals("")) {
                    DatosFormularioBusqueda(obj.getObjcadena());
                }
                cConexion.cerrar();
            } catch (Exception ex) {
                Logger.getLogger(Frm_Clientes.class.getName()).log(Level.SEVERE, null, ex);
            }

            //        DatosfrmBusq(obj.getObjcli());
            jButtonAceptar.setEnabled(true);
        }
    }//GEN-LAST:event_jButtonBuscarActionPerformed

    private void jButtonAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAceptarActionPerformed

        //codigo para realizar las diferentes tareas Insert,Update,Delete
        Exception e;
        if (CamposNulos() == true) {//verifico que campo se encuentra vacio y advierto
            JOptionPane.showMessageDialog(null, txtnulos, "Campos Vacios", JOptionPane.INFORMATION_MESSAGE);
            txtnulos = "Los Campos Vacios son:\n";
        } else {//Inicio la Insercion
            if (jRadioButtonInsert.isSelected() == true) {
                cCategoria obj1 = new cCategoria();
                DatosFormulario(obj1);
                try {
                    e = AD_Categoria.Insertar(obj1);
                    if (e == null) {
                        JOptionPane.showMessageDialog(null, "Se ha sido ingresado correctamente", "INSERTAR", JOptionPane.INFORMATION_MESSAGE);
                    } else {
                        JOptionPane.showMessageDialog(null, "Existe el siguiente error:\n" + e, "ERROR AL INSERTAR", JOptionPane.ERROR_MESSAGE);
                    }
                    dispose();
                    cConexion.cerrar();
                } catch (Exception ex) {
                    Logger.getLogger(Frm_Clientes.class.getName()).log(Level.SEVERE, null, ex);
                }
            }//Terminamos con la Insercion
            else {//Inicio de Actualizacion
                if (jRadioButtonUpdate.isSelected() == true) {
                    cCategoria obj1 = new cCategoria();
                    DatosFormulario(obj1);
                    try {

                        e = AD_Categoria.Actualizar(obj1);
                        if (e == null) {
                            JOptionPane.showMessageDialog(null, "Los datos se han actualizado correctamente", "MODIFICAR", JOptionPane.INFORMATION_MESSAGE);
                        } else {
                            JOptionPane.showMessageDialog(null, "Existe el siguiente error:\n" + e, "ERROR AL MODIFICAR", JOptionPane.ERROR_MESSAGE);
                        }
                        dispose();
                        cConexion.cerrar();
                    } catch (Exception ex) {
                        Logger.getLogger(Frm_Clientes.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }//terminanos con la Actualizacion
                else {//Iniciamos la Eliminacion
                    try {

                        e = AD_Categoria.Eliminar(jTextFieldNomCategoria.getText());
                        if (e == null) {
                            JOptionPane.showMessageDialog(null, "Los datos se han Eliminado correctamente", "ELIMINAR", JOptionPane.INFORMATION_MESSAGE);
                        } else {
                            JOptionPane.showMessageDialog(null, "Existe el siguiente error:\n" + e, "ERROR AL ELIMINAR", JOptionPane.ERROR_MESSAGE);
                        }
                        dispose();
                        cConexion.cerrar();
                    } catch (Exception ex) {
                        Logger.getLogger(Frm_Clientes.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }//Terminamos la Eliminacion
            }
        }
    }//GEN-LAST:event_jButtonAceptarActionPerformed

    private void jButtonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelarActionPerformed
        try {
            // TODO add your handling code here:
            dispose();
            cConexion.cerrar();
        } catch (Exception ex) {
            Logger.getLogger(Frm_Clientes.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButtonCancelarActionPerformed

    private void jTextFieldCodigoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldCodigoKeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldCodigoKeyTyped

    private void jTextFieldNomCategoriaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldNomCategoriaKeyTyped
        // TODO add your handling code here:
        char t = evt.getKeyChar();
        if (t == java.awt.event.KeyEvent.VK_ENTER){            
            jTextFieldGDistrib.requestFocus();            
        }
    }//GEN-LAST:event_jTextFieldNomCategoriaKeyTyped

    private void jTextFieldGDistribKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldGDistribKeyTyped
        // TODO add your handling code here:
        char t = evt.getKeyChar();
        if (!((t >= '0' && t <= '9') || t == '.') || jTextFieldGDistrib.getText().length() > 3) {
            evt.setKeyChar('\b');
        }
        if (t == java.awt.event.KeyEvent.VK_ENTER){            
            jTextFieldGCF.requestFocus();
        }
    }//GEN-LAST:event_jTextFieldGDistribKeyTyped

    private void jTextFieldGCFKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldGCFKeyTyped
        // TODO add your handling code here:
        char t = evt.getKeyChar();
        if (!((t >= '0' && t <= '9') || t == '.') || jTextFieldGCF.getText().length() > 3) {
            evt.setKeyChar('\b');
        }
        if (t == java.awt.event.KeyEvent.VK_ENTER){
            jButtonAceptar.requestFocus();
        }
    }//GEN-LAST:event_jTextFieldGCFKeyTyped

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Frm_Categoria.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Frm_Categoria.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Frm_Categoria.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Frm_Categoria.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new Frm_Categoria().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jButtonAceptar;
    private javax.swing.JButton jButtonBuscar;
    private javax.swing.JButton jButtonCancelar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabelCodigo;
    private javax.swing.JLabel jLabelNomCategoria;
    private javax.swing.JPanel jPanelBotones;
    private javax.swing.JPanel jPanelDatos;
    private javax.swing.JPanel jPanelOpciones;
    private javax.swing.JRadioButton jRadioButtonDelete;
    private javax.swing.JRadioButton jRadioButtonInsert;
    private javax.swing.JRadioButton jRadioButtonUpdate;
    private javax.swing.JTabbedPane jTabbedPaneDatos;
    private javax.swing.JTextField jTextFieldCodigo;
    private javax.swing.JTextField jTextFieldGCF;
    private javax.swing.JTextField jTextFieldGDistrib;
    private javax.swing.JTextField jTextFieldNomCategoria;
    // End of variables declaration//GEN-END:variables
}
